home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / tsrcomm.zip / TSRCOMM.ASM < prev    next >
Assembly Source File  |  1987-09-09  |  63KB  |  2,061 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;    TSRCOMM.ASM        A Replacement for Interrupt 14
  3. ;;
  4. ;;    Copyright    1987, Ross M. Greenberg
  5. ;;
  6. ;;    This program is a terminate and stay resident program which allows
  7. ;;    computers such as the IBM PC and compatibles using standard serial
  8. ;;    communications calls to take advantage of the asynchronous interrupt
  9. ;;    capabilities of the 8250 and 8259.
  10. ;;
  11. ;;    The functionality with AH=0,1,2,3 remains the same as always
  12. ;;
  13. ;;    With AH = 4, a new set of commands are now available.
  14. ;;    Sub-functions are set in AL (See below for new function descriptions)
  15. ;;
  16. ;;    To compile this program, you must have MASM 4.0 or a close relative,
  17. ;;    and need only do:
  18. ;;
  19. ;;    C> MASM TSRCOMM;
  20. ;;    C> LINK TSRCOMM;
  21. ;;    C> EXE2BIN TSRCOMM.EXE TSRCOMM.COM
  22. ;;    C> DEL TSRCOMM.EXE
  23. ;;
  24. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  25.  
  26. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  27. ;;
  28. ;;                MACRO DEFINITIONS
  29. ;;
  30. DOSINT    macro    set_ah_to
  31.     mov    ah, set_ah_to
  32.     int    21h
  33. endm
  34. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  35.  
  36.  
  37. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  38. ;;
  39. ;;                CONSTANTS
  40. ;;
  41. FALSE        equ    00h
  42. TRUE        equ    01h    
  43. BELL        equ    07h
  44. ONE_SECOND    equ    18        ; roughly 18 timer ticks
  45. TWO_SECONDS    equ    ONE_SECOND * 2    ; same idea
  46. THIRTY_SECONDS    equ    ONE_SECOND * 30 ;
  47.  
  48.  
  49.  
  50. TIMER_TICK_INT_NO    equ    1ch    ; some might set this to 08h
  51.  
  52.  
  53. ;;    Send an XOFF when you wish the remote to stop sending and
  54. ;;    send an XON when the remote is allowed to continue
  55. ;;
  56.  
  57. XOFF    equ    13h    ; a control-S
  58. XON    equ    11h    ; a control-Q
  59.  
  60.  
  61.  
  62. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  63. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  64. ;;    Define the size of the Communications Buffers
  65. ;;    
  66. ;;    You may want to change these to more accurately reflect your
  67. ;;    actual needs.  The high-water and low-water mark for XON/XOFF
  68. ;;    processing are a function of the size of these two variables
  69.  
  70. P1_INLEN    equ    400h
  71. P2_INLEN    equ    400h
  72. P1_OUTLEN    equ    400h
  73. P2_OUTLEN    equ    400h
  74.  
  75. ;; Be careful with these settings if your have different lengths for each
  76. ;; of the COM_INBUF's: these only play off of COM1_INBUF
  77.  
  78. HIGH_MARK    equ    (P1_INLEN/10 * 8)    ; send XOFF when buffer is
  79.                         ; 80% full
  80. LOW_MARK    equ    (P1_INLEN/10 * 2)    ; send XON when buffer is
  81.                         ; only 20% full
  82. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  83. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  84.  
  85.  
  86. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  87. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  88. ;;
  89. ;;    Definitions of all of the 8250 Registers and their individual
  90. ;;    bit meanings
  91. ;;
  92. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  93. DATA        equ    0h    ; DATA I/O is from the base
  94.  
  95. IER        equ    1h    ; Interrupt Enable Register
  96.  IER_RDA    equ    1h    ;  Received Data Available interrupt bit
  97.  IER_THRE    equ    2h    ;  Transmitter Holding Reg. Empty int bit
  98.  IER_RLS    equ    4h    ;  Receive Line Status int bit
  99.  IER_MS        equ    8h    ;  Modem Status int bit
  100.  
  101. IIR        equ    2    ; Interrupt Identification Register
  102.  IIR_RLS    equ    5h    ;  *equal* to if Receiver Line Status int
  103.  IIR_RDA    equ    4h    ;  *equal* to if character ready
  104.  IIR_THRE    equ    2h    ;  *equal* to if TX Buffer empty
  105.  IIR_PEND    equ    1h    ;  set to zero if any interrupt pending
  106.  IIR_MS        equ    0h    ;  *equal* to if Modem Status int
  107.  
  108. LCR        equ    3h    ; Line Control Register
  109.  LCR_WLS0    equ    0h    ;  Word Length Select Bit 0
  110.  LCR_WLS1    equ    1h    ;  Word Length Select Bit 1
  111.  LCR_STOPBITS    equ    4h    ;  number of stop bits
  112.  LCR_PARITYEN    equ    8h    ;  Enable Parity (see SPARITY & EPARITY)
  113.  LCR_EPARITY    equ    10h    ;  Even Parity Bit
  114.  LCR_SPARITY    equ    20h    ;  Stick Parity
  115.  LCR_BREAK    equ    40h    ;  set if break is desired
  116.  LCR_DLAB    equ    80h    ;  Divisor Latch Access Bit (baudrate setting)
  117.  
  118. MCR        equ    4h    ; Modem Control Register
  119.  MCR_DTR    equ    1h    ;  Data Terminal Ready
  120.  MCR_RTS    equ    2h    ;  Request To Send
  121.  MCR_OUT1    equ    4h    ;  Output 1 (nobody uses this!)
  122.  MCR_OUT2    equ    8h    ;  Out 2 (Sneaky Int enable in hware gates!)
  123.  MCR_LOOP    equ    10h    ;  Loopback enable
  124.  
  125. LSR        equ    5    ; Line Status Register
  126.   LSR_DATA    equ    1h    ;  Data Ready Bit
  127.   LSR_OVERRUN    equ    2h    ;  Overrun Error Bit
  128.   LSR_PARITY    equ    4h    ;  Parity Error Bit
  129.   LSR_FRAMING    equ    8h    ;  Framing Error Bit
  130.   LSR_BREAK    equ    10h    ;  Break Detect (sometimes an error!)
  131.   LSR_THRE    equ    20h    ;  Transmit Holding Register Empty
  132.   LSR_TSRE    equ    40h    ;  Transmit Shift Register Empty
  133.  
  134. MSR        equ    6    ; Modem Status Register
  135.   MSR_DEL_CTS    equ    1h    ;  Delta Clear To Send
  136.   MSR_DEL_DSR    equ    2h    ;  Delta Data Set Ready
  137.   MSR_EDGE_RI    equ    4h    ;  Trailing Edge of Ring Indicator
  138.   MSR_DEL_SIGD    equ    8h    ;  Delta Receive Line Signal Detect (delta DCD)
  139.   MSR_CTS    equ    10h    ;  Clear To Send
  140.   MSR_DSR    equ    20h    ;  Data Set Ready
  141.   MSR_RI    equ    40h    ;  Ring Indicator - during the entire ring
  142.   MSR_DCD    equ    80h    ;  Data Carrier Detect - Someone On-line
  143. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  144. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  145.  
  146. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  147. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  148. ;;    The 8259 interrupt controller is at port I/O INT_CTRL
  149. ;;    To reset from an interrupt, you must output an INT_EOI.
  150. ;;
  151. ;;    To enable or disable interrupts for either of the com ports, read
  152. ;;    the value on port INT_MASK_PORT, turn the appropriate COM1 or COM2 bit
  153. ;;    on or off, and output the new mask back out the port.
  154. ;;
  155. ;;
  156. CTRL_PORT    equ    20h
  157. INT_EOI        equ    20h
  158. ;;
  159. INT_MASK_PORT    equ    21h
  160. COM1_MASK    equ    0efh
  161. COM2_MASK    equ    0f7h
  162. INTNO_COM1    equ    0ch
  163. INTNO_COM2    equ    0bh
  164. ;;
  165. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  166. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  167.  
  168. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  169. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  170. ;;    These ports may or may not respond to the ports at base 40:0.
  171. ;;    If they don't we'll refuse to run.  Not at all subtle, but effective.
  172. ;;    See the first Sidebar for more information
  173. ;;
  174. PORT1    equ    3f8h
  175. PORT2    equ    2f8h
  176. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  177. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  178.  
  179.  
  180. code    segment    para        ; align the code segment to the nearest
  181.                 ; paragraph boundary
  182. assume    cs:code
  183. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  184. org    2ch
  185. env_ptr    label    word        ; this points to the environment address
  186.                 ; as stored in the PSP. We'll free this
  187.                 ; in the startup routine.
  188.  
  189. org    100h            ; COM programs always start at 100h
  190.                 ; just like CP/M!
  191.  
  192. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  193. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  194. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  195. ;;                START OF TSR CODE
  196. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  197. start:    jmp    install
  198.  
  199.  
  200.  
  201. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  202. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  203. ;;            COMM PORT BLOCK    (CPB)
  204. ;;
  205. ;;    Comm Port Block defines information unique for each comm port
  206. ;;    and includes information such as what the original interrupt
  207. ;;    vector pointed to, which parameters are set, etc.
  208. ;;
  209. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  210. CPB    struc
  211.  
  212. cpb_base    dw    ?    ; the base port of the comm port (2F8, 3F8)
  213. cpb_nint_off    dw    ?    ; new interrupt offset address
  214. cpb_pic_mask    db    ?    ; mask for enabling ints from 8259
  215. cpb_int_no    db    ?    ; what interrupt we are
  216.  
  217. cpb_mode    dw    ?    ; whatever modes we have turned on
  218. cpb_timeout    dw    ?    ; indi